{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import chipwhisperer as cw\n",
    "try:\n",
    "    if not scope.connectStatus:\n",
    "        scope.con()\n",
    "except NameError:\n",
    "    scope = cw.scope()\n",
    "    \n",
    "target = cw.target(scope)\n",
    "prog=None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(\"***********************************************\")\n",
    "print(\"1. Ensure J3 on UFO Board routines CLKFB to HS1/IN\")\n",
    "print (\"2. Confirm baud settings\")\n",
    "    \n",
    "scope.gain.gain = 45\n",
    "scope.adc.samples = 25000\n",
    "scope.adc.offset = 0\n",
    "scope.adc.basic_mode = \"rising_edge\"\n",
    "scope.clock.clkgen_freq = 7370000\n",
    "scope.clock.adc_src = \"extclk_x1\"\n",
    "scope.trigger.triggers = \"tio4\"\n",
    "#TX/RX backwards from XMEGA\n",
    "scope.io.tio1 = \"serial_tx\"\n",
    "scope.io.tio2 = \"serial_rx\"\n",
    "scope.io.hs2 = None\n",
    "\n",
    "#Sample delay - you may need to increase this!\n",
    "time.sleep(0.5)\n",
    "\n",
    "ext_freq = scope.clock.freq_ctr\n",
    "\n",
    "if ext_freq > 10:\n",
    "\n",
    "    baud = int((115200 / 32E6) * ext_freq)\n",
    "    print(\"Based on extclk of %d Hz, setting baud to %d\" % (ext_freq, baud))\n",
    "    target.baud = baud\n",
    "    \n",
    "else:\n",
    "    raise IOError(\"Did not detect external clock from D2000. Confirm jumpers and rerun, or increase delay before sample.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
